// 表单属性【右面板】
import { i18n } from "@/i18n";
import {
  inputConfig,
  numberConfig,
  textareaConfig,
  selectConfig,
  radioConfig,
  checkboxConfig,
  advancedComponents,
  composeComponents,
  fileConfig,
  imageConfig,
  horizontalInputConfig,
  matrixInputConfig,
  matrixSelectConfig,
  matrixScaleConfig,
  matrixSliderConfig,
  matrixDropdownConfig,
  tableSelectConfig
} from "./config";

export const evaluationConf = {
  formRef: "elForm",
  formModel: "formData",
  size: "mini",
  labelPosition: "top",
  labelWidth: 100,
  formRules: "rules",
  gutter: 20,
  disabled: false,
  span: 24,
  title: i18n.global.t("formgen.config.evaluationTile"),
  description: i18n.global.t("formgen.config.description"),
  formBtns: true,
  unFocusedComponentBorder: true
};

const evalMatrixSelectConfig = {
  ...matrixSelectConfig,
  multiple: undefined,
  notAllowRowEditable: true,
  table: {
    rows: [
      {
        label: i18n.global.t("formgen.config.evalUser1"),
        id: 1
      },
      {
        label: i18n.global.t("formgen.config.evalUser2"),
        id: 2
      },
      {
        label: i18n.global.t("formgen.config.evalUser3"),
        id: 3
      }
    ],
    columns: [
      {
        label: i18n.global.t("formgen.config.col1"),
        id: 1,
        score: 1
      },
      {
        label: i18n.global.t("formgen.config.col2"),
        id: 2,
        score: 2
      },
      {
        label: i18n.global.t("formgen.config.col3"),
        id: 3,
        score: 3
      }
    ]
  }
};

const evalMatrixScaleConfig = {
  ...matrixScaleConfig,
  table: {
    rows: [
      {
        label: i18n.global.t("formgen.config.evalUser1"),
        id: 1
      },
      {
        label: i18n.global.t("formgen.config.evalUser2"),
        id: 2
      },
      {
        label: i18n.global.t("formgen.config.evalUser3"),
        id: 3
      }
    ],
    copyWriting: {
      max: i18n.global.t("formgen.config.min"),
      min: i18n.global.t("formgen.config.max")
    },
    level: 5
  }
};

const evalMatrixSliderConfig = {
  ...matrixSliderConfig,
  table: {
    rows: [
      {
        label: i18n.global.t("formgen.config.evalUser1"),
        id: 1
      },
      {
        label: i18n.global.t("formgen.config.evalUser2"),
        id: 2
      },
      {
        label: i18n.global.t("formgen.config.evalUser3"),
        id: 3
      }
    ]
  }
};

const evalBasicComponents = [
  inputConfig,
  numberConfig,
  textareaConfig,
  selectConfig,
  radioConfig,
  checkboxConfig,
  fileConfig,
  imageConfig
];

// 基础组件 【基础组件】
export const evaluationComponents = [evalMatrixScaleConfig, evalMatrixSelectConfig, evalMatrixSliderConfig];

export const allComponents = [
  {
    title: i18n.global.t("formgen.config.evaluationComponents"),
    list: evaluationComponents
  },
  {
    title: i18n.global.t("formgen.config.basicComponents"),
    list: evalBasicComponents
  },
  {
    title: i18n.global.t("formgen.config.composeComponents"),
    list: composeComponents
  }
];

interface ComponentsObj {
  [key: string]: any;
}

export let componentsObj: ComponentsObj = {};

export function getEvaluationComponentsObj() {
  if (!componentsObj) {
    initComponentsObj();
  }
  return componentsObj;
}

export function initComponentsObj() {
  componentsObj = {};
  allComponents.forEach(comps => {
    comps.list.forEach(item => {
      if (!componentsObj[item.typeId]) {
        componentsObj[item.typeId] = item;
      }
    });
  });
}

export default { allComponents };
